<template>
  <!-- 微信登录 -->
  <!-- <button
    class="WX-login-btn"
    open-type="getUserInfo"
    @getuserinfo="getuserinfo"
  >
    微信登录
  </button> -->
  <view @click="handleLogin">微信登录</view>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { wxLoginApi } from "@/api/login.js";
import { useUserStore } from "@/stores/user";

// pinia
// 如果要用解构  要收用storeToRefs才能变为响应式
// const { userInfo } = storeToRefs(user);
// async function handleLogin() {
//   let userInfo = await userInfoApi();
//   console.log(userInfo);
//   user.setUserInfo(userInfo);
// }
const user = useUserStore();

const handleLogin = () => {
  uni.login({
    success: (res) => {
      wxLoginApi({
        appCode: "1",
        code: res.code,
      }).then((res) => {
        console.log(res);
        user.setToken(res.data.tokenValue);
      });
    },
  });
};
</script>
